package com.starleague.hexagonal;

public abstract class AbstractHexCoordinate
        implements IHexCoordinate
{
    private int gridX;
    private int gridY;

    protected AbstractHexCoordinate(int gridX,
                                    int gridY)
    {
        this.gridX = gridX;
        this.gridY = gridY;
    }

    protected AbstractHexCoordinate(IHexCoordinate hexCoordinate)
    {
        this.gridX = hexCoordinate.getGridX();
        this.gridY = hexCoordinate.getGridY();
    }

    protected AbstractHexCoordinate()
    {
        //
    }

    @Override
    public int getGridX()
    {
        return this.gridX;
    }

    protected void setGridX(int gridX)
    {
        this.gridX = gridX;
    }

    @Override
    public int getGridY()
    {
        return this.gridY;
    }

    protected void setGridY(int gridY)
    {
        this.gridY = gridY;
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + this.gridX;
        result = prime * result + this.gridY;
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (!(obj instanceof IHexCoordinate))
            return false;
        IHexCoordinate other = (IHexCoordinate) obj;
        if (this.gridX != other.getGridX())
            return false;
        if (this.gridY != other.getGridY())
            return false;
        return true;
    }

    @Override
    public String toString()
    {
        return this.getClass().getSimpleName() + "[" + this.gridX + ", " + this.gridY + "]";
    }
}
